<?php

namespace app\admin\controller;

use auth\Auth;
use app\admin\model\Admin;
use app\admin\model\Config;

class Index extends Common
{
    protected $middleware = [ 
        'app\admin\middleware\CheckAuth' => ['only' 		=> ['index'] ],
    ];
    
    /**
     * 首页
     * @return mixed
     */
    public function index()
    {
       //echo 1;die;
        //获取菜单
        $menuList = (new Auth($this->uid, $this->group_id))->getMenuList();
        $this->assign('menuList', $menuList);
        $info = Admin::get($this->uid)->hidden(['password']);
        $info['head'] ? : $info['head'] = '/images/face.jpg';
        $this->assign('info', $info);
        //公告
        $notice_config = $this->noticeConfig();
        $this->assign('notice_config', $notice_config);
        
        $a = input('a');
        if($a && $a == 1){
            $url = url('/admin/bianma-edit');
        } else{
            $url = url('/admin/home');
        }
        $this->assign('url', $url);
        return $this->fetch();
    }

    /**
     * layui 首页
     * @return mixed
     */
    public function home()
    {
        return $this->fetch();
    }

    /**
     * 公告配置信息
     */
    private function noticeConfig()
    {
        $notice_config = cache('notice_config');
        if ($notice_config) {
            return $notice_config;
        }
        $list = Config::where('name', '=', 'notice_config')->field('value')->find();
        cache('notice_config', $list);
        return $list;
    }
}
